package com.toe.user.webapi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.toe.pojo.dto.user.UserAdminRoleAddDTO;
import com.toe.pojo.entity.user.UserAdminRole;
import com.toe.pojo.vo.user.UserAdminRoleVO;
import com.toe.user.service.UserAdminRoleService;
import com.toe.user.webapi.mapper.UserAdminRoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@Service
@Slf4j
public class UserAdminRoleServiceImpl extends ServiceImpl<UserAdminRoleMapper, UserAdminRole> implements UserAdminRoleService {

    @Autowired
    private UserAdminRoleMapper userAdminRoleMapper;

    @Override
    public void insert(UserAdminRoleAddDTO userAdminRoleAddDTO) {
        UserAdminRole userAdminRole = new UserAdminRole();
        BeanUtils.copyProperties(userAdminRoleAddDTO,userAdminRole);
        LocalDateTime data = LocalDateTime.now();
        userAdminRole.setCreateTime(data);
        userAdminRole.setUpdateTime(data);
        userAdminRoleMapper.insert(userAdminRole);
    }

    @Override
    public void delete(long id) {
        userAdminRoleMapper.deleteById(id);
    }

    @Override
    public List<UserAdminRoleVO> selectAllAdminRole() {
        List<UserAdminRoleVO> userAdminRoleVOS = userAdminRoleMapper.selectAllAdminRole();
        return userAdminRoleVOS;
    }

    @Override
    public Boolean selectOneAdminRole(long adminId, long roleId) {
        UserAdminRoleVO userAdminRoleVO = userAdminRoleMapper.selectOneAdminRole(adminId, roleId);
        if (userAdminRoleVO==null)
            return false;
        return true;
    }

    @Override
    public void deleteOne(long adminId, long roleId) {
        userAdminRoleMapper.deleteOne(adminId,roleId);
    }
}
